package com.project.nimsen.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.project.jdbc.dao.IBaseJdbcDao;
import com.project.jdbc.service.BaseServiceImpl;
import com.project.jdbc.utils.Finder;
import com.project.nimsen.dao.IBaseDao;
import com.project.nimsen.dto.MenuDto;
import com.project.nimsen.service.ISMenuService;
@Repository("sMenuService")
public class SMenuServiceImpl extends BaseServiceImpl implements ISMenuService {
	@Resource
	IBaseDao baseDao;
	protected IBaseJdbcDao getBaseDao() {
		return baseDao;
	}
	public List<Map<String, Object>> findByDto(MenuDto dto) throws Exception {
		Finder finder = new Finder("select m.* from S_MENU m where m.active!=1");
		if(dto==null){
			return baseDao.queryForList(finder);
		}
		if(StringUtils.isNotBlank(dto.getPcode())){
			if(dto.isFindAllChild()){
				finder.append(" and code like ").append(dto.getPcode()).append("-%");
			}else{
				finder.append(" and p_code=:pcode");
				finder.setParam("pcode", dto.getPcode());
			}
		}else{
			if(!dto.isFindAllChild()){
				finder.append(" and p_code='0' or p_code is null or p_code=''");
			}
		}
		finder.append(" order by m.id asc");
		return baseDao.queryForList(finder);
	}
}